
//2012年上半年下午JAVA试题答案
//http://eol.shengda.edu.cn/meol/homepage/course/course_hwtask_view.jsp?_style=null&hwtid=3571
package cn.edu.shengda;
abstract class Beverage{
    String description="Unknow Beverage";
    public abstract  int cost();
    public String getDescription() {
        return description;
    }
}
//配料
abstract class CondimentDecorator extends Beverage{
    Beverage beverage;
}
//蒸馏咖啡
class Espresso extends Beverage{
    private final int ESPRESSO_PRICE=25;
    public Espresso(){ description="Espresso";}
    public int cost(){return ESPRESSO_PRICE;}
}
//深度烘培咖啡
class DarkRoast extends Beverage{
    private final int DARKROAST_PRICE=20;
    public DarkRoast(){description="DarkRoast";}
    public int cost(){return DARKROAST_PRICE;}
}
class Mocha extends CondimentDecorator{
    private final int MOCHA_PRICE=10;
    public Mocha(Beverage beverage){
        this.beverage=beverage;
    }
    public String getDescription(){
        return beverage.getDescription()+", Mocha";
    }
    public int cost(){
        return MOCHA_PRICE + beverage.cost();
    }
}
class Whip extends CondimentDecorator{
    private final int WHIP_PRICE=8;
    public Whip(Beverage beverage){
        this.beverage=beverage;
    }
    public String getDescription(){
        return beverage.getDescription()+", Whip";
    }
    public int cost(){
        return WHIP_PRICE + beverage.cost();
    }
}

public class Coffee {
    public static void main(String[] args) {
        Beverage beverage=new Espresso();
        beverage=new Mocha(beverage);
        beverage=new Whip(beverage);
        System.out.println(beverage.getDescription()+"$"+
                beverage.cost());
    }
}
